package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.mall.dto.ProductDetailRequest;
import com.cskaoyan.mall.dto.ProductDetailResponse;
import com.cskaoyan.shopping.converter.ProductDetailConventer;
import com.cskaoyan.shopping.dto.AllProductRequest;
import com.cskaoyan.shopping.dto.AllProductResponse;
import com.cskaoyan.shopping.dto.RecommendResponse;
import com.cskaoyan.shopping.form.PageInfo;
import com.cskaoyan.shopping.form.PageResponse;
import com.cskaoyan.shopping.service.IProductService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: DYQ
 * @time: Created on 2022/6/19 15:20
 */

@RestController
public class ShoppingProductDetailController {

    @Autowired
    IProductService productService;

    @Autowired
    ProductDetailConventer productDetailConventer;

    @GetMapping("/shopping/product/{pid}")
    public ResponseData getProductDetail(@PathVariable("pid") long id) {

        ProductDetailRequest request = new ProductDetailRequest();
        request.setId(id);

        ProductDetailResponse response = productService.getProductDetail(request);

        if (ShoppingRetCode.SUCCESS.getCode().equalsIgnoreCase(response.getCode())) {
            return new ResponseUtil().setData(response.getProductDetailDto());
        }

        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

    @GetMapping("/shopping/goods")
    public ResponseData queryListOfGoods(PageInfo pageInfo) {

        AllProductRequest request = productDetailConventer.pageInfo2AllProductRequset(pageInfo);

        PageResponse response = productService.getAllProduct(request);

        return new ResponseUtil().setData(response);
    }

    @GetMapping("/shopping/recommend")
    public ResponseData queryRecommend() {

        RecommendResponse response = productService.getRecommendGoods();

        return new ResponseUtil().setData(response.getPanelContentItemDtos());
    }

}
